package com.cetcs.kmga.dataManager.util;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.io.IOException;
import java.util.Properties;

/**
 * @Title: 读取配置文件工具类
 * @Package: com.cetc.cloud.ldmp.common.util
 * @Description: 读取配置文件的工具类
 * @Author: Xutao
 * @Date: 2016/11/18 11:15
 * @Version V1.0
 * @Copyright ©2016 by CETC
 */
public class ReadConfigUtil {
    static Properties props = null;


    /**
     * 通过key获取配置文件里面的值
     *
     * @param key 关键字
     * @return
     */
    public static String getValueByKey(String fileUrl, String key) {

        try {
            Resource res = new ClassPathResource(fileUrl);
            EncodedResource encRes = new EncodedResource(res,"UTF-8");
            Properties props= PropertiesLoaderUtils.loadProperties(encRes);
//            Properties props = PropertiesLoaderUtils.loadAllProperties(fileUrl);
            return props.getProperty(key);
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException();
        }
    }
    public static void main(String[] args){
        String admin = getValueByKey("conf\\logService.properties","log_admin");
        System.out.print(admin);
    }
}
